using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace WindowsGame1.CoreComponents
{
    public abstract class Sprite
    {
        protected Texture2D texture;
        protected Rectangle sourceRectangle;
        protected Vector2 position;
        protected Vector2 velocity;
        protected Vector2 center;
        protected float scale;
        protected float rotation;
        protected SpriteBatch spriteBatch;
        protected int width;
        protected int height;

        public Sprite(Game game, Texture2D texture)
        {
            spriteBatch =
            (SpriteBatch)game.Services.GetService(typeof(SpriteBatch));
            this.texture = texture;
            width = texture.Width;
            height = texture.Height;
            position = Vector2.Zero;
            velocity = Vector2.Zero;
            center = new Vector2(texture.Width / 2,
            texture.Height / 2);
            scale = 1.0f;
            rotation = 0.0f;
            sourceRectangle = new Rectangle(0,
            0,
            texture.Width,
            texture.Height);
        }

        public Sprite(Game game, Texture2D texture, Rectangle sourceRectangle)
        {
            spriteBatch =
            (SpriteBatch)game.Services.GetService(typeof(SpriteBatch));
            this.texture = texture;
            this.sourceRectangle = sourceRectangle;
            position = Vector2.Zero;
            velocity = Vector2.Zero;
            center = new Vector2(sourceRectangle.Width / 2,
            sourceRectangle.Height / 2);
            width = sourceRectangle.Width;
            height = sourceRectangle.Height;
            scale = 1.0f;
            rotation = 0.0f;
        }

        public abstract void Update(GameTime gameTime);

        public abstract void Draw(GameTime gameTime);

        public Rectangle Bounds
        {
            get
            {
                return new Rectangle(
                (int)position.X,
                (int)position.Y,
                width,
                height);
            }
        }

        public virtual Texture2D Texture
        {
            get { return texture; }
        }

        public virtual Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        public virtual Vector2 Velocity
        {
            get { return velocity; }
        }

        public virtual Vector2 Center
        {
            get { return center; }
        }

        public Vector2 Origin
        {
            get { return position + center; }
        }

        public virtual float Scale
        {
            get { return scale; }
        }

        public virtual float Rotation
        {
            get { return rotation; }
        }

        public int Width
        {
            get { return width; }
        }

        public int Height
        {
            get { return height; }
        }
    }
}